<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
	<xsl:variable name="isAssociation" select="true()" />
	<xsl:template match="*" mode="Id">
		<xsl:value-of select="@xmi.id"/>
	</xsl:template>
	<xsl:template match="*" mode="IdRef">
		<xsl:value-of select="@xmi.idref"/>
	</xsl:template>
	<xsl:template match="*" mode="Value">
		<xsl:value-of select="@xmi.value"/>
	</xsl:template>
	<xsl:template match="*" mode="Name">
		<xsl:value-of select="@name"/>
	</xsl:template>
	<xsl:template match="*" mode="Navigability">
		<xsl:value-of select="@isNavigable"/>
	</xsl:template>
	<xsl:template match="*" mode="Visibility">
		<xsl:choose>
			<xsl:when test="@visibility">
				<xsl:value-of select="@visibility"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:text>private</xsl:text>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="*" mode="IsRoot">
		<xsl:value-of select="@isRoot"/>
	</xsl:template>
	<xsl:template match="*" mode="IsAbstract">
		<xsl:value-of select="@isAbstract"/>
	</xsl:template>
	<xsl:template match="*" mode="IsLeaf">
		<xsl:value-of select="@isLeaf"/>
	</xsl:template>
	<xsl:template match="*" mode="IsActive">
		<xsl:value-of select="@isActive"/>
	</xsl:template>
	<xsl:template match="*" mode="Stereotype">
		<xsl:variable name="idRef" select="@stereotype"/>
		<xsl:value-of select="//Stereotype[@xmi.id=$idRef]/@name"/>
	</xsl:template>
	<xsl:template match="*" mode="Type">
		<xsl:variable name="id">
			<xsl:choose>
				<xsl:when test="self::Operation">
					<xsl:value-of select="BehavioralFeature.parameter/Parameter[@kind='return']/@type"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="@type"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:choose>
			<!-- si le type n'est pas défini -->
			<xsl:when test="//DataType[@xmi.id=$id]/@name = '' or //DataType[@xmi.id=$id]/@name= '&amp;lt;undefined&amp;gt;'">
				<xsl:text>void</xsl:text>
			</xsl:when>
			<!-- si le type est défini -->
			<xsl:otherwise>
				<xsl:value-of select="//DataType[@xmi.id=$id]/@name"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="*" mode="Documentation">
		<xsl:variable name="id" select="@xmi.id"/>
		<xsl:value-of select="//TaggedValue[@modelElement=$id and @name='documentation']/TaggedValue.dataValue"/>
	</xsl:template>
	<xsl:template match="*" mode="DefaultValue">
		<xsl:value-of select="Attribute.initialValue/Expression/Expression.body | Attribute.initialValue/Expression/@body"/>
	</xsl:template>
	<xsl:template match="*" mode="IsEntryParameter">
		<xsl:if test="@kind='in' or @kind='inout'">
			<xsl:value-of select="true()"/>
		</xsl:if>
	</xsl:template>
	<!-- ________________________________________________________________________________________________________ -->
	<!--												Les TEMPLATES									       -->
	<!-- ________________________________________________________________________________________________________ -->
	<!-- ****************** template attribute 'NAME' ****************** -->
	<xsl:template name="AttributeName">
		<xsl:param name="node"/>
		<xsl:variable name="name">
			<xsl:apply-templates select="$node" mode="Name"/>
		</xsl:variable>
		<xsl:attribute name="name"><xsl:if test="$name=''"><xsl:apply-templates select="." mode="Id"/></xsl:if><xsl:value-of select="$name"/></xsl:attribute>
	</xsl:template>
	<!-- ****************** template attribute 'VISIBILITY' ****************** -->
	<xsl:template name="AttributeVisibility">
		<xsl:param name="node"/>
		<xsl:attribute name="visibility"><xsl:text>v_</xsl:text><xsl:apply-templates select="." mode="Visibility"/></xsl:attribute>
	</xsl:template>
	<!-- ****************** template attribute 'ISROOT' ****************** -->
	<xsl:template name="AttributeIsRoot">
		<xsl:param name="node"/>
		<xsl:attribute name="isRoot"><xsl:apply-templates select="$node" mode="IsRoot"/></xsl:attribute>
	</xsl:template>
	<!-- ****************** template attribute 'ABSTRACT' ****************** -->
	<xsl:template name="AttributeAbstract">
		<xsl:param name="node"/>
		<xsl:attribute name="abstract"><xsl:apply-templates select="$node" mode="IsAbstract"/></xsl:attribute>
	</xsl:template>
	<!-- ****************** template attribute 'ISLEAF' ****************** -->
	<xsl:template name="AttributeIsLeaf">
		<xsl:param name="node"/>
		<xsl:attribute name="isLeaf"><xsl:apply-templates select="$node" mode="IsLeaf"/></xsl:attribute>
	</xsl:template>
	<!-- ****************** template attribute 'ISACTIVE' ****************** -->
	<xsl:template name="AttributeIsActive">
		<xsl:param name="node"/>
		<xsl:attribute name="isActive"><xsl:apply-templates select="$node" mode="IsActive"/></xsl:attribute>
	</xsl:template>
	<!-- ****************** template attribute 'STEREOTYPE' ****************** -->
	<xsl:template name="AttributeStereotype">
		<xsl:param name="node"/>
		<xsl:attribute name="stereotype"><xsl:apply-templates select="$node" mode="Stereotype"/></xsl:attribute>
	</xsl:template>
	<!-- ****************** template attribute 'TYPE' ****************** -->
	<xsl:template name="AttributeType">
		<xsl:param name="node"/>
		<xsl:attribute name="type"><xsl:apply-templates select="$node" mode="Type"/></xsl:attribute>
	</xsl:template>
	<!-- ****************** template attribute 'DOCUMENTATION' ****************** -->
	<xsl:template name="AttributeDocumentation">
		<xsl:param name="node"/>
		<xsl:attribute name="documentation"><xsl:apply-templates select="$node" mode="Documentation"/></xsl:attribute>
	</xsl:template>
	<!-- ****************** template attribute 'DEFAULTVALUE' ****************** -->
	<xsl:template name="AttributeDefaultValue">
		<xsl:param name="node"/>
		<xsl:attribute name="defaultValue"><xsl:apply-templates select="$node" mode="DefaultValue"/></xsl:attribute>
	</xsl:template>
	<!-- ****************** template element 'PARAMETER' ****************** -->
	<xsl:template name="ElementParameter">
		<xsl:param name="node"/>
		<xsl:for-each select="$node/BehavioralFeature.parameter/Parameter">
			<xsl:variable name="isEntryParameter">
				<xsl:apply-templates select="." mode="IsEntryParameter"/>
			</xsl:variable>
			<xsl:if test="$isEntryParameter='true'">
				<xsl:element name="Parameter">
					<xsl:call-template name="AttributeName">
						<xsl:with-param name="node" select="."/>
					</xsl:call-template>
					<xsl:call-template name="AttributeType">
						<xsl:with-param name="node" select="."/>
					</xsl:call-template>
					<xsl:call-template name="AttributeDocumentation">
						<xsl:with-param name="node" select="."/>
					</xsl:call-template>
				</xsl:element>
			</xsl:if>
		</xsl:for-each>
	</xsl:template>
	<!-- ________________________________________________________________________________________________________ -->
	<!--												Les TEMPLATES pour les ASSOCIATIONS				       -->
	<!-- ________________________________________________________________________________________________________ -->
	<xsl:template match="Generalization" mode="Generalization.child_idRef">
		<xsl:value-of select="Generalization.child//@xmi.idref"/>
	</xsl:template>
	<xsl:template match="Generalization" mode="Generalization.parent_idRef">
		<xsl:value-of select="Generalization.parent//@xmi.idref"/>
	</xsl:template>
	<xsl:template match="Abstraction | Dependency" mode="Abstraction.client_idRef">
		<xsl:value-of select="Dependency.client//@xmi.idref"/>
	</xsl:template>
	<xsl:template match="Abstraction | Dependency" mode="Abstraction.supplier_idRef">
		<xsl:value-of select="Dependency.supplier//@xmi.idref"/>
	</xsl:template>
	<xsl:template match="AssociationEnd" mode="Association.participant_idRef">
		<xsl:value-of select="AssociationEnd.participant//@xmi.idref"/>
	</xsl:template>
	<xsl:template match="AssociationEnd" mode="Aggregation">
		<xsl:value-of select="@aggregation"/>
	</xsl:template>
	<xsl:template match="Association | AssociationClass" mode="Navigable">
		<xsl:variable name="client">
			<xsl:apply-templates select="." mode="AssociationClient"/>
		</xsl:variable>
		<xsl:variable name="clientNavigability">
			<xsl:apply-templates select="Association.connection/AssociationEnd[position()=$client]" mode="Navigability"/>
		</xsl:variable>
		<xsl:variable name="associationType">
			<xsl:apply-templates select="." mode="AssociationType"/>
		</xsl:variable>
		<xsl:choose>
			<xsl:when test="$associationType='association'">false</xsl:when>
			<xsl:otherwise>
				<xsl:choose>
					<xsl:when test="$clientNavigability='true'">false</xsl:when>
					<xsl:otherwise>true</xsl:otherwise>
				</xsl:choose>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="Association | AssociationClass" mode="RoleName">
		<xsl:param name="role"/>
		<xsl:variable name="roleClient">
			<xsl:apply-templates select="." mode="AssociationClient"/>
		</xsl:variable>
		<xsl:variable name="roleSupplier">
			<xsl:apply-templates select="." mode="AssociationSupplier"/>
		</xsl:variable>
		<xsl:variable name="associationName">
			<xsl:apply-templates select="Association.connection/AssociationEnd[position()=$role]" mode="Name"/>
		</xsl:variable>
		<xsl:choose>
			<xsl:when test="$role=$roleClient and ($associationName='undefined' or not($associationName) or $associationName='')">
				<xsl:apply-templates select="." mode="ClientClassName"/>
				<xsl:apply-templates select="Association.connection/AssociationEnd[position()=$roleSupplier]" mode="Name"/>
				<xsl:text>Parent</xsl:text>
			</xsl:when>
			<xsl:otherwise>
				<xsl:apply-templates select="Association.connection/AssociationEnd[position()=$role]" mode="Name"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="Association | AssociationClass" mode="GetAssociationClassifier">
		<xsl:value-of select="@name"/>
	</xsl:template>
	<xsl:template match="Association | AssociationClass" mode="xmiMultiplicity">
		<xsl:param name="role"/>
		<xsl:apply-templates select="Association.connection/AssociationEnd[position()=$role]" mode="MultiplicityLower"/>
		<xsl:text>..</xsl:text>
		<xsl:apply-templates select="Association.connection/AssociationEnd[position()=$role]" mode="MultiplicityUpper"/>
	</xsl:template>
	<xsl:template match="AssociationEnd" mode="MultiplicityLower">
		<xsl:choose>
			<xsl:when test="AssociationEnd.multiplicity/Multiplicity/Multiplicity.range/MultiplicityRange/@upper='-1'">
				<xsl:text>*</xsl:text>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="AssociationEnd.multiplicity/Multiplicity/Multiplicity.range/MultiplicityRange/@lower"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="AssociationEnd" mode="MultiplicityUpper">
		<xsl:choose>
			<xsl:when test="AssociationEnd.multiplicity/Multiplicity/Multiplicity.range/MultiplicityRange/@upper='-1'">
				<xsl:text>*</xsl:text>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="AssociationEnd.multiplicity/Multiplicity/Multiplicity.range/MultiplicityRange/@upper"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<!-- ****************** template attribute 'ASSOCIATIONCLASSNAME' ****************** -->
	<xsl:template name="AttributeAssociationClassifier">
		<xsl:param name="node"/>
		<xsl:attribute name="associationClassifier"><xsl:apply-templates select="$node" mode="GetAssociationClassifier"/></xsl:attribute>
	</xsl:template>
	<!-- ****************** template attribute 'CLIENTCLASSNAME' ****************** -->
	<xsl:template name="AttributeClientClassName">
		<xsl:param name="node"/>
		<xsl:attribute name="clientClassName"><xsl:apply-templates select="$node" mode="ClientClassName"/></xsl:attribute>
	</xsl:template>
	<xsl:template match="Dependency | Abstraction | Generalization | Association | AssociationClass" mode="ClientClassName">
		<xsl:variable name="idRef">
			<xsl:apply-templates select="." mode="IdRefClient"/>
		</xsl:variable>
		<xsl:apply-templates select="//*[@xmi.id=$idRef]" mode="Name"/>
	</xsl:template>
	<xsl:template match="Dependency | Abstraction | Generalization | Association | AssociationClass" mode="IdRefClient">
		<xsl:choose>
			<xsl:when test="self::Generalization">
				<xsl:apply-templates select="." mode="Generalization.child_idRef"/>
			</xsl:when>
			<xsl:when test="self::Abstraction">
					<xsl:apply-templates select="." mode="Abstraction.client_idRef" />
				</xsl:when>
			<xsl:when test="self::Dependency">
					<xsl:apply-templates select="." mode="Abstraction.client_idRef" />
				</xsl:when>
			<xsl:when test="self::Association | self::AssociationClass">
				<xsl:variable name="no">
					<xsl:apply-templates select="." mode="AssociationClient"/>
				</xsl:variable>
				<xsl:apply-templates select="Association.connection/AssociationEnd[position()=$no]" mode="Association.participant_idRef"/>
			</xsl:when>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="Association | AssociationClass" mode="AssociationClient">
		<xsl:variable name="class1">
			<xsl:apply-templates select="Association.connection/AssociationEnd[1]" mode="Aggregation"/>
		</xsl:variable>
		<xsl:choose>
			<xsl:when test="$class1='none'">2</xsl:when>
			<xsl:otherwise>1</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<!-- ****************** template attribute 'SUPPLIERCLASSNAME' ****************** -->
	<xsl:template name="AttributeSupplierClassName">
		<xsl:param name="node"/>
		<xsl:attribute name="supplierClassName"><xsl:apply-templates select="$node" mode="SupplierClassName"/></xsl:attribute>
	</xsl:template>
	<xsl:template match="Dependency | Abstraction | Generalization | Association | AssociationClass" mode="SupplierClassName">
		<xsl:variable name="idRef">
			<xsl:apply-templates select="." mode="IdRefSupplier"/>
		</xsl:variable>
		<xsl:apply-templates select="//*[@xmi.id=$idRef]" mode="Name"/>
	</xsl:template>
	<xsl:template match="Dependency | Abstraction | Generalization | Association | AssociationClass" mode="IdRefSupplier">
		<xsl:choose>
			<xsl:when test="self::Generalization">
				<xsl:apply-templates select="." mode="Generalization.parent_idRef"/>
			</xsl:when>
			<xsl:when test="self::Abstraction">
					<xsl:apply-templates select="." mode="Abstraction.supplier_idRef" />
			</xsl:when>
			<xsl:when test="self::Dependency">
					<xsl:apply-templates select="." mode="Abstraction.supplier_idRef" />
			</xsl:when>
			<xsl:when test="self::Association | self::AssociationClass">
				<xsl:variable name="no">
					<xsl:apply-templates select="." mode="AssociationSupplier"/>
				</xsl:variable>
				<xsl:apply-templates select="Association.connection/AssociationEnd[position()=$no]" mode="Association.participant_idRef"/>
			</xsl:when>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="Association | AssociationClass" mode="AssociationSupplier">
		<xsl:variable name="class1">
			<xsl:apply-templates select="Association.connection/AssociationEnd[1]" mode="Aggregation"/>
		</xsl:variable>
		<xsl:choose>
			<xsl:when test="$class1='none'">
				<xsl:text>1</xsl:text>
			</xsl:when>
			<xsl:otherwise>2</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<!-- ****************** template attribute 'TYPE' ****************** -->
	<xsl:template name="AttributeAssociationType">
		<xsl:param name="node"/>
		<xsl:attribute name="type"><xsl:apply-templates select="$node" mode="AssociationType"/></xsl:attribute>
	</xsl:template>
	<xsl:template match="Association | AssociationClass" mode="AssociationType">
		<xsl:variable name="class1">
			<xsl:apply-templates select="Association.connection/AssociationEnd[1]" mode="Aggregation"/>
		</xsl:variable>
		<xsl:variable name="class2">
			<xsl:apply-templates select="Association.connection/AssociationEnd[2]" mode="Aggregation"/>
		</xsl:variable>
		<xsl:choose>
			<xsl:when test="$class1='none' and $class2='none'">association</xsl:when>
			<xsl:when test="$class1='aggregate' or $class2='aggregate'">aggregation</xsl:when>
			<xsl:when test="$class1='shared' or $class2='shared'">aggregation</xsl:when>
			<xsl:when test="$class1='composite' or $class2='composite'">composition</xsl:when>
		</xsl:choose>
	</xsl:template>
	<!-- ****************** template attribute 'NAVIGABLE' ****************** -->
	<xsl:template name="AttributeNavigable">
		<xsl:param name="node"/>
		<xsl:attribute name="navigable"><xsl:apply-templates select="$node" mode="Navigable"/></xsl:attribute>
	</xsl:template>
	<!-- ****************** template attribute 'CLIENTMULTIPLICITY' ****************** -->
	<xsl:template name="AttributeClientMultiplicity">
		<xsl:param name="node"/>
		<xsl:variable name="roleClient">
			<xsl:apply-templates select="$node" mode="AssociationClient"/>
		</xsl:variable>
		<xsl:attribute name="clientMultiplicity"><xsl:apply-templates select="$node" mode="Multiplicity"><xsl:with-param name="role" select="$roleClient"/></xsl:apply-templates></xsl:attribute>
	</xsl:template>
	<!-- ****************** template attribute 'SUPPLIERMULTIPLICITY' ****************** -->
	<xsl:template name="AttributeSupplierMultiplicity">
		<xsl:param name="node"/>
		<xsl:variable name="roleSupplier">
			<xsl:apply-templates select="$node" mode="AssociationSupplier"/>
		</xsl:variable>
		<xsl:attribute name="supplierMultiplicity"><xsl:apply-templates select="$node" mode="Multiplicity"><xsl:with-param name="role" select="$roleSupplier"/></xsl:apply-templates></xsl:attribute>
	</xsl:template>
	<xsl:template match="Association | AssociationClass" mode="Multiplicity">
		<xsl:param name="role"/>
		<xsl:variable name="xmiMultiplicity">
			<xsl:apply-templates select="." mode="xmiMultiplicity">
				<xsl:with-param name="role" select="$role"/>
			</xsl:apply-templates>
		</xsl:variable>
		<xsl:choose>
			<xsl:when test="$xmiMultiplicity='1..*'">
				<xsl:text>0..*</xsl:text>
			</xsl:when>
			<xsl:when test="$xmiMultiplicity='1..1'">
				<xsl:text>1</xsl:text>
			</xsl:when>
			<xsl:when test="$xmiMultiplicity='*..*'">
				<xsl:text>0..*</xsl:text>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$xmiMultiplicity"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<!-- ****************** template attribute 'CLIENTROLE' ****************** -->
	<xsl:template name="AttributeClientRole">
		<xsl:param name="node"/>
		<xsl:variable name="roleClient">
			<xsl:apply-templates select="$node" mode="AssociationClient"/>
		</xsl:variable>
		<xsl:attribute name="clientRole"><xsl:apply-templates select="$node" mode="RoleName"><xsl:with-param name="role" select="$roleClient"/></xsl:apply-templates></xsl:attribute>
	</xsl:template>
	<!-- ****************** template attribute 'SUPPLIERROLE' ****************** -->
	<xsl:template name="AttributeSupplierRole">
		<xsl:param name="node"/>
		<xsl:variable name="roleSupplier">
			<xsl:apply-templates select="$node" mode="AssociationSupplier"/>
		</xsl:variable>
		<xsl:attribute name="supplierRole"><xsl:apply-templates select="$node" mode="RoleName"><xsl:with-param name="role" select="$roleSupplier"/></xsl:apply-templates></xsl:attribute>
	</xsl:template>
	<!-- ________________________________________________________________________________________________________ -->
	<!--												Les FONCTIONS A SURCHARGER					       -->
	<!-- ________________________________________________________________________________________________________ -->
	<!-- ****************** noeud 'Generalization' ****************** -->
	<xsl:template match="Generalization">
		<xsl:variable name="idRef" select="Generalization.parent/GeneralizableElement/@xmi.idref"/>
		<xsl:variable name="stereotype">
			<xsl:apply-templates select="//Class[@xmi.id=$idRef]/@stereotype" mode="Stereotype"/>
		</xsl:variable>
		<xsl:choose>
			<xsl:when test="$stereotype='interface'">
				<xsl:apply-templates select="." mode="Implementation"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="Generalization"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<xsl:template name="IsAssociationClass">
		<xsl:param name="id"/>
		<xsl:value-of select="false()"/>
	</xsl:template>
	<xsl:template name="IsAssociationClassifier">
		<xsl:param name="node"/>
		<xsl:value-of select="false()"/>
	</xsl:template>
</xsl:stylesheet>
